package com.lenovo.lcdm.integration.utils;

import cn.hutool.json.JSONUtil;
import com.lenovo.lcdm.integration.config.KafkaProducerContext;
import com.lenovo.lcdm.integration.entity.EndpointConfig;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

public class KafkaHelper {

    public static void publish(String name, String data) {
        EndpointConfig endpointConfigMap = KafkaProducerContext.getEndpointConfigMap(name);
        KafkaProducer<String, String> producer = new KafkaProducer<>(JSONUtil.parseObj(endpointConfigMap.getConnectionInfo()));
        producer.send(new ProducerRecord<>(endpointConfigMap.getTopic(), data));
        producer.close();
    }
}
